package ar.edu.utn.frba.dds.opendesigners;

import java.util.List;
import java.math.BigDecimal;
import java.util.ArrayList;

import ar.edu.utn.frba.dds.opendesigners.exception.ExceptionInvalidSeat;

public class SearchResponse {
	private List<RouteOption> list;

	public SearchResponse() {
		this.list = new ArrayList<RouteOption>();
	}

	public void add(RouteOption route) {
		this.list.add(route);
	}

	public void addAll(SearchResponse routeOptionList) {
		this.list.addAll(routeOptionList.getList());
	}

	public SearchResponse filterPrice(BigDecimal price) {
		List<RouteOption> copyList = new ArrayList<RouteOption>(this.list);
		for (RouteOption route : this.list) {
			if (route.priceBiggerThan(price))
				copyList.remove(route);
		}
		this.list = copyList;
		return this;
	}

	public SearchResponse surchargePrice(BigDecimal ammount) {
		for (RouteOption route : this.list) {
			route.addToPrice(ammount);
		}
		return this;
	}

	public RouteOption selectSeat(String flightNum, String seatNum) {
		for (RouteOption route : this.list) {
			if (route.getFlightNumber().equals(flightNum)
					&& route.getSeatNumber().equals(seatNum))
				return route;
		}
		throw new ExceptionInvalidSeat();
	}

	public RouteOption selectSeat(int position) {
		return this.list.get(position);
	}

	public List<RouteOption> getList() {
		return this.list;
	}

	public boolean equals(SearchResponse search) {
		return this.getList().equals(search.getList());
	}
}
